<template>
	<section>

		<!--列表-->
		<el-table :data="users" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column prop="rid" label="ID" width="100" sortable>
			</el-table-column>
			<el-table-column prop="mid" label="消息ID" sortable>
			</el-table-column>
			<el-table-column prop="uid" label="举报人ID" sortable>
			</el-table-column>
			<el-table-column prop="date" label="举报时间" :formatter="formatDate" sortable>
			</el-table-column>
			<el-table-column prop="adminid" label="处理人" sortable>
			</el-table-column>
			<el-table-column prop="time" label="处理时间" :formatter="formatTime" sortable>
			</el-table-column>
			<el-table-column prop="opresult" label="处理结果" :formatter="formateOpresult" sortable>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template scope="scope">
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row, 1)">合法</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row, 2)">非法</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量非法</el-button>
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getReports, checkReport, batchCheckReport } from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				users: [],
				total: 0,
				page: 1,
				groups: [],
				listLoading: false,
				sels: [],//列表选中列

				editFormVisible: false,//编辑界面是否显示
				editLoading: false,
				editFormRules: {
				},
				//编辑界面数据
				editForm: {
				},

				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
				},
				//新增界面数据
				addForm: {
				}

			}
		},
		methods: {
			//时间显示转换
			formatTime: function (row, column) {
				if(row.time != 0 && row.time!=undefined ){
					var thisdate = new Date(row.time*1000);
					return thisdate.getFullYear()+"-"+(thisdate.getMonth()+1)+"-"+thisdate.getDate();
				}else{
					return "无";
				}
			},
			//日期显示转换
			formatDate: function (row, column) {
				if(row.time!=undefined && row.date != 0){
					var thisdate = new Date(row.date*1000);
					return thisdate.getFullYear()+"-"+(thisdate.getMonth()+1)+"-"+thisdate.getDate();
				}else{
					return "无";
				}
			},
			//处理人
			formateAdminid: function (row, column){
				if(row.adminid == 0){
					return '无';
				}else{
					return row.adminid;
				}
			},
			//处理结果
			formateOpresult: function (row, column){
				if(row.opresult == 1){
					return '合法';
				}else if(row.opresult == 2){
					return '非法';
				}else if(row.opresult == 3){
					return '未审核';
				}
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers() {
				let para = {
					'page': this.page
				};
				this.listLoading = true;
				var vue = this;
				//NProgress.start();
				getReports(para).then((res) => {
					// console.log('suc');
					if(res.data.id == 1){
						vue.$alert(res.message, '读取失败', {
						confirmButtonText: '确定',
						callback: action => {}
						});
					}else if(res.data.id == 0){
						this.users = res.data.message;
						this.total = res.data.total;
						//this.total = res.message.length;
					}
					//NProgress.done();
					this.listLoading = false;
				}).catch((error) => {
					this.$notify.error({
					title: '无法连接到服务器',
					message: '请检查您的网络连接，稍后重试'
					});
				});
			},
			//审核
			handleDel: function (index, row, op) {
				this.$confirm('确认审核该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { id: row.rid, op: op };
					checkReport(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						if(res.data.id == 0){
							this.$message({
								message: res.data.message,
								type: 'success'
							});
							this.getUsers();
						}else if(res.data.id == 1){
							this.$message({
								message: res.data.message,
								type: 'danger'
							});
						}
					}).catch((error) => {
						this.$notify.error({
							title: '无法连接到服务器',
							message: '请检查您的网络连接，稍后重试'
						});
					});
				}).catch(() => {

				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.rid).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
					batchCheckReport(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			}
		},
		mounted() {
			this.getUsers();
		}
	}

</script>

<style scoped>

</style>